﻿using System;
using System.Collections.Generic;
using System.Text;
using Stonecode.Solar.ParticleEngine.Emitters;
using Microsoft.Xna.Framework;
using System.ComponentModel;

namespace Stonecode.Solar.ParticleEngine
{
    public class EmitterTypeSettings
    {
        private EmitterType _emitterType;
        public EmitterType EmitterType { get { return _emitterType; } }

        public EmitterTypeSettings()
        {
            // this fixes a sparatic issue with the importer
            // where it doesn't ever get a Point type... but works with
            // everything else
            _emitterType = EmitterType.Point;
        }
        public EmitterTypeSettings(EmitterType et)
        {
            _emitterType = et;
        }
    }

    public class PointEmitterTypeSettings : EmitterTypeSettings
    {
        public bool EllipticalVelocity { get; set; }
        public PointEmitterTypeSettings()
            : base(EmitterType.Point)
        {
            EllipticalVelocity = true;
        }
    }
    public class CircleEmitterTypeSettings : EmitterTypeSettings
    {
        public float Radius { get; set; }
        public bool RadiateOutward { get; set; }
        public float StartAngle { get; set; }
        public float EndAngle { get; set; }

        public CircleEmitterTypeSettings()
            : base(EmitterType.Circle)
        {
            Radius = 0f;
            RadiateOutward = true;
            StartAngle = 0f;
            EndAngle = 0f;
        }
        public CircleEmitterTypeSettings(float radius, bool radiateOutward)
            : base(EmitterType.Circle)
        {
            Radius = radius;
            RadiateOutward = radiateOutward;
            StartAngle = 0f;
            EndAngle = 0f;
        }
    }

    public class LineEmitterTypeSettings : EmitterTypeSettings
    {
        private float _rotation;
        public Matrix mRot;
        //public Matrix mNegRot;
        //public Matrix mRot90;

        private float _halfLength;
        public float LineLength 
        {
            get { return _halfLength * 2f; }
            set { _halfLength = value * .5f; }
        }

        public float HalfLength { get { return _halfLength; } }

        public float Rotation 
        {
            get { return _rotation; }
            set
            {
                _rotation = value;
                mRot = Matrix.CreateRotationZ(value);
                //mNegRot = Matrix.CreateRotationZ(-value);
            }
        }

        public bool PerpendicularVelocity { get; set; }

        public LineEmitterTypeSettings()
            : base(EmitterType.Line)
        {
            LineLength = 0f;
            Rotation = 0f;
            PerpendicularVelocity = true;
        }
        public LineEmitterTypeSettings(float lineLength, float rotation, bool pv)
            : base(EmitterType.Line)
        {
            LineLength = lineLength;
            Rotation = rotation;
            PerpendicularVelocity = pv;
        }
    }

    public class RectangleEmitterTypeSettings : EmitterTypeSettings
    {
        // [TypeConverter(typeof(ExpandableObjectConverter))]
        public RectangleF Rectangle { get; set; }
        public float Width
        {
            get { return Rectangle.Width; }
            set 
            {
                RectangleF rec = Rectangle;
                rec.Width = value;
                Rectangle = rec;
            }
        }
        public float Height
        {
            get { return Rectangle.Height; }
            set
            {
                RectangleF rec = Rectangle;
                rec.Height = value;
                Rectangle = rec;
            }
        }

        private bool _radiateOutward;
        public bool RadiateOutward
        {
            get { return _radiateOutward; }
            set
            {
                if (!_createOnEdge)
                    _radiateOutward = false;
                else
                    _radiateOutward = value;

            }
        }
        private bool _createOnEdge;
        public bool CreateOnEdge 
        {
            get { return _createOnEdge; }
            set
            {
                _createOnEdge = value;
                if (!value) _radiateOutward = false;
            }
        }
        public Matrix mRot;
        private float _rotation;
        public float Rotation 
        {
            get { return _rotation; }
            set
            {
                _rotation = value;
                mRot = Matrix.CreateRotationZ(value);
            }
        }

        public bool RotateVelocity { get; set; }

        public RectangleEmitterTypeSettings()
            : base(EmitterType.Rectangle)
        {
            Rectangle = new RectangleF(Vector2.Zero, 0f, Vector2.Zero);
            Rotation = 0;
            RotateVelocity = true;
            CreateOnEdge = false;
        }
        public RectangleEmitterTypeSettings(RectangleF rec, float rot, bool rv)
            : base(EmitterType.Rectangle)
        {
            Rectangle = rec;
            Rotation = rot;
            RotateVelocity = rv;
            CreateOnEdge = false;
        }
    }

}
